<%-- 
    Document   : cartStep2
    Created on : Apr 17, 2013, 5:07:26 PM
    Author     : Illya
--%>

<%@page import="java.util.List"%>
<%@page import="com.charlie.beans.Users"%>
<%@page import="com.charlie.beans.Warehouse"%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@include file="/header.jsp"%>

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.11&libraries=places&sensor=false"></script>
<script type="text/javascript">
    var warehouse_list = [
    <%
        List<Warehouse> warehouse_list = (List<Warehouse>) request.getAttribute("warehouse_list");
        if (warehouse_list != null) {
            for (Warehouse wh : warehouse_list) {
    %>
            {
                id: <%= wh.getWarehouseId()%>,
                name: "<%= wh.getName()%>",
                position: "<%= wh.getLocation()%>",
                cost_rate: <%= wh.getShipmentRate()%>,
                duration_rate: <%= wh.getShipmentDuration()%>,
                point: null
            },
    <%
            }
        }
    %>
        ];
</script>
<script type="text/javascript" src="/resources/js/order.js"></script>

<h2 class="content_title">Delivery path</h2>
<table class="white_block">
    <tr>
        <td colspan="2">
            <h2 style="text-align: center; margin-top: 4px; margin-bottom: 15px;">Select warehouse and location where you want to receive guitars</h2>
        </td>
    </tr>
    <tr>
        <td>
            <div id="map-canvas"></div>
        </td>
        <td style="vertical-align: top;">
            <div id="wh_list" style="margin-left: 10px;"></div>
            <p style="margin-left: 10px"> Warehouse location:<br>
                <span style="margin-left: 10px" id="whAddress"></span>
            </p>
            <p style="margin-left: 10px">Your location (U)<br>
                <%
                if (user == null) { %>
                <input style="margin-left: 10px" id="search" type="text" size="40" value="<%= cart.getLocation() %>">
                <% } else {
                    out.print(user.getLocation());
                } %>
                
            </p>
            <div id="result" style="margin-left: 10px">
                Distance: <span id="distance"></span><br>
                Delivery time: <span id="del_time"></span><br>
                Price for shipping: <span id="price"><br></span> $
                <br><br>
                <form method="post">
                    <input type="hidden" name="distance" value="0">
                    <input type="hidden" name="warehouse_id" value="${cart.getWarehouse()}">
                    <input type="hidden" name="destination" value="<%= (user == null) ? cart.getLocation() : user.getLocation() %>">
                    <input type="submit" value="Complete the purchase" style="float: right;">
                </form>
            </div>
            <div id="error_path_not_found" class="error_msg">Path not found</div>
        </td>
    </tr>
</table>

<jsp:include page="/footer.jsp" />
